package com.linzm.server;

import com.linzm.utils.HttpProtocolUtil;
import lombok.SneakyThrows;

import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * v1 简单 的 输入输出
 *
 * @Date: 2023/11/6 21:37
 * @User linziming
 */
public class Bootstrap {
    @SneakyThrows
    public static void main(String[] args) {
        ServerSocket serverSocket = new ServerSocket(8080);
        while (true) {
            Socket socket = serverSocket.accept();
            OutputStream outputStream = socket.getOutputStream();
            String data = "Hello Mini-tomcat!";
            String responseText = HttpProtocolUtil.getHttpHeader200(data.getBytes().length) + data;
            outputStream.write(responseText.getBytes());
            socket.close();
        }
    }
}
